package com.chainyoung.component_tmtrade.ui.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.chainyoung.common.imageloader.ImageLoader;
import com.chainyoung.common.imageloader.glide.GlideImageConfig;
import com.chainyoung.common.utils.ConvertUtils;
import com.chainyoung.common.utils.Utils;
import com.chainyoung.component_tmtrade.R;
import com.chainyoung.component_tmtrade.R2;
import com.chainyoung.component_tmtrade.bean.CurrencyMarketList;


import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;



public class TradeCoupleAdapter extends BaseAdapter {

    private Context mContext;
    private List<CurrencyMarketList.MarketListBean> dataSet;
    private ImageLoader imageLoader;

    public TradeCoupleAdapter(Context context, List<CurrencyMarketList.MarketListBean> data) {
        this.mContext = context;
        this.dataSet = data;
        imageLoader = Utils.getAppComponent().imageLoader();
    }

    @Override
    public int getCount() {
        return dataSet.size();
    }

    @Override
    public Object getItem(int position) {
        return dataSet.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.tmtrade_list_trade_couple_item, null);
            convertView.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        CurrencyMarketList.MarketListBean item = dataSet.get(position);

        viewHolder.tvName.setText(item.getName());
        imageLoader.loadImage(mContext,
                GlideImageConfig
                        .builder()
                        .url(item.getImg())
                        .imagerView(viewHolder.ivLogo)
                        .build());
        return convertView;
    }

    static class ViewHolder {
        @BindView(R2.id.iv_logo)
        ImageView ivLogo;
        @BindView(R2.id.tv_name)
        TextView tvName;


        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
